<?php
if( !defined('IN_INDEX') )
{
	die('This page is hidden.');
}
function redirect($url)
{
?>
	<script type="text/javascript">
		{
		window.location = "<?php echo $url?>";
		}
	</script>
<?php 
}
if(!checkSession())
{
			
			redirect("index.php?action=profile&sub=edit");
	exit;
}
include('inc/functions_award.php');
include('inc/functions_blog.php');

$dateformat_long = $CONFIG['date_format_long'];

?>
<script type="text/javascript" src="./jscript/jquery.bgiframe.min.js"></script>
<script type="text/javascript" src="./jscript/date.js"></script>
<script type="text/javascript" src="./jscript/jquery.datePicker.js"></script>
<link rel="stylesheet" href="./jscript/generalstyle.css" type="text/css" media="screen" charset="utf-8" />
<link rel="stylesheet" href="./jscript/datePicker.css" type="text/css" media="screen" charset="utf-8" />

<div id='postpath'>
	<a title="<?php echo translate('gotofrontpage'); ?>" href="index.php"><?php echo translate('home'); ?></a>
    &gt; <a href="index.php?action=blogs" title='<?php echo translate('showallblogs'); ?>'><?php echo translate('blog'); ?></a> 
    &gt; <a href="index.php?action=profile&id=<?php echo $USER->getId(); ?>"><?php echo ucf($USER->getFirstname()) . " " . ucf($USER->getLastname()); ?></a>
	&gt; <a href="index.php?action=profile&sub=edit" title='<?php echo translate('edit'); ?>'><?php echo translate('edit'); ?></a> 
	&gt; <a href="index.php?action=profile&sub=edit_admin" title='<?php echo translate('aminsettings'); ?>'><?php echo translate('adminsettings'); ?></a> &gt; <a href="index.php?action=profile&sub=new_award" title='<?php echo translate('newawardheader'); ?>'><?php echo translate('newawardheader'); ?></a>
</div>
<br />
<?php
if(isset($_GET['aid'])){
?>
<h1><?php echo translate('editawardheader'); ?></h1>
<?php
}else{
?>
<h1><?php echo translate('newawardheader'); ?></h1>

<?php
}
?>

<?php
	if(isset($_POST['award-submit'])){
		$awardData['name'] = $_POST['award-name'];
		$awardData['gender'] = $_POST['gender'];
		$awardData['category'] = $_POST['category'];
		$awardData['requirement'] = $_POST['award-requirement'];
		
		if($_POST['award-body-weight'] ==""){
			$awardData['bodyweight'] = "0";
		}else{
			$awardData['bodyweight'] = $_POST['award-body-weight'];
		}
		if($_POST['select_category'] == ""){
			$awardData['category_exercise']= -1;
		}else{
			$awardData['category_exercise']= $_POST['select_category'];
		}
		if($_POST['exercise'] == ""){
			$awardData['exercise'] = -1;
		}else{
			$awardData['exercise'] = $_POST['exercise'];
		}
		
		$awardData['level'] = $_POST['level'];
		$awardData['point'] = $_POST['award-point'];	
		$awardData['image'] = "";
		$imgName = $_FILES['award-image']['name'];
		$imgSize = $_FILES['award-image']['size'];
		$imgTmp_name = $_FILES['award-image']['tmp_name'];
		
		
		if($_POST['award-num-of-repetition'] ==""){
			$awardData['num_of_repitition'] = 0;
		}else{
			$awardData['num_of_repitition'] = $_POST['award-num-of-repetition'];
		}
		if($_POST['award-sets-per-hour'] ==""){
			$awardData['awardSetsPerHour'] = 0;
		}else{
			$awardData['awardSetsPerHour'] = $_POST['award-sets-per-hour'];
		}
		
		if($_POST['award-repetitions-per-hour'] ==""){
			$awardData['awardRepetitionsPerHour'] = 0;
		}else{
			$awardData['awardRepetitionsPerHour'] = $_POST['award-repetitions-per-hour'];
		}
		
		if($_POST['award-from-date'] ==""){
			$awardData['awardFromDate'] = 0;
		}else{
			$awardData['awardFromDate'] = strtotime($_POST['award-from-date']);
		}
		if($_POST['award-to-date'] ==""){
			$awardData['awardToDate'] = 0;
		}else{
			$awardData['awardToDate'] = strtotime($_POST['award-to-date']);
		}
		
		$awardData['periodTime'] = $_POST['period-time'];
		
		if(substr($imgName, strpos($imgName, '.') + 1) == "JPG" || substr($imgName, strpos($imgName, '.') + 1) == "jpg" || substr($imgName, strpos($imgName, '.') + 1) == "jpeg" || substr($imgName, strpos($imgName, '.') + 1) == "JPEG" || substr($imgName, strpos($imgName, '.') + 1) == "png" || substr($imgName, strpos($imgName, '.') + 1) == "PNG")
		{
			// Start upload process
			$saving_name = time()."_$imgName";
			$location = "./img/award_pic/$saving_name";
			// Move picture to folder
			move_uploaded_file($imgTmp_name, $location);
			$awardData['image'] = $saving_name;
		}
		if(isset($_GET['aid'])){
			$awardData['id'] = $_GET['aid'];
			$return = updateAward($awardData);
		}else{
			$return = insertAward($awardData);
		}
		if($return){
			redirect("index.php?action=profile&sub=awardlist");
		}
	}else{
		if(isset($_GET['aid'])){
			$result = getAwardById($_GET['aid']);
			$awardData = array();
			while ($row = mysql_fetch_array($result )){
				$awardData['name'] = $row['award_name'];
				$awardData['gender'] = $row['gender'];
				$awardData['category'] = $row['category'];
				$awardData['requirement'] = $row['requirement'];
				$awardData['bodyweight'] = $row['body_weight'];
				$awardData['category_exercise'] = $row['category_exercise'];
				$awardData['exercise'] = $row['exercise'];
				$awardData['level'] = $row['level'];
				$awardData['point'] = $row['point'];
				$awardData['image'] = $row['image'];
				$awardData['num_of_repitition'] = $row['num_of_repitition'];
				$awardData['awardSetsPerHour'] = $row['sets'];
				$awardData['awardRepetitionsPerHour'] = $row['repetition'];
				$awardData['awardFromDate'] = $row['from_date'];
				$awardData['awardToDate'] = $row['to_date'];
				$awardData['periodTime'] = $row['period_time'];
			}
			if(!isset($awardData['name'])){
				redirect("index.php?action=profile&sub=stats_awards");
			}
		}else{
			$awardData['name'] = "";
			$awardData['gender'] = "";
			$awardData['category'] = "volume";
			$awardData['requirement'] = "";
			$awardData['bodyweight'] = "";
			$awardData['category_exercise'] = "";
			$awardData['exercise'] = "";
			$awardData['level'] = "";
			$awardData['point'] = "";	
			$awardData['image'] = "";
			$awardData['num_of_repitition'] = "";
			$awardData['awardSetsPerHour'] = "";
			$awardData['awardRepetitionsPerHour'] = "";
			$awardData['awardFromDate'] = "";
			$awardData['awardToDate'] = "";
			$awardData['periodTime'] = "";
		}
	}
?>

<form action="" method="POST" name="new_award" enctype="multipart/form-data">
	<div class="new-award-wrapper">
		<div class="new-award-item">
			<div class="new-award-item-left">
				<label for=""><?php echo translate('nameofachievement');?>:</label>
			</div>
			<div class="new-award-item-right">
				<input type="text" value="<?php echo $awardData['name']?>" name="award-name" />
			</div>
			<div class="clear"></div>
		</div>
		
		<?php
			$genderStyle = "";
			if($awardData['category'] != "effectiveness"){
				$genderStyle = "display:none;";
			}
		?>
		
		<div id="gender-item" class="new-award-item">
			<div class="new-award-item-left">
				<label for=""><?php echo translate('gender');?>:</label>
			</div>
			<div class="new-award-item-right">
				<select class="select" id="gender" name="gender">
					<option value=""><?php echo translate('both')?></option>
					<?php
					if($awardData['gender'] == "male"){
					?>
					<option selected="selected" value="male"><?php echo translate('male'); ?></option>
					<?php
					}else{
					?>
					<option value="male"><?php echo translate('male'); ?></option>
					<?php
					}
					?>
					<?php
					if($awardData['gender'] == "female"){
					?>
					<option selected="selected" value="female"><?php echo translate('female');?></option>
					<?php
					}else{
					?>
					<option value="female"><?php echo translate('female');?></option>
					<?php
					}
					?>
            	</select>
			</div>
			<div class="clear"></div>
		</div>
		<div class="new-award-item">
			<div class="new-award-item-left">
				<label for=""><?php echo translate('categories');?>:</label>
			</div>
			<div class="new-award-item-right">
				<select class="select" id="category" name="category">
					<option <?php echo ($awardData['category']=="volume")?"selected='selected'":"";?> value="volume"><?php echo translate('volume'); ?></option>
					<option <?php echo ($awardData['category']=="weight")?"selected='selected'":"";?> value="weight"><?php echo translate('weight'); ?></option>
					<option <?php echo ($awardData['category']=="bodyweight")?"selected='selected'":"";?> value="bodyweight"><?php echo translate('bodyweight'); ?></option>
					<option <?php echo ($awardData['category']=="numberofconnections")?"selected='selected'":"";?> value="numberofconnections"><?php echo translate('numberofconnections'); ?></option>
					<option <?php echo ($awardData['category']=="halloffameplacment")?"selected='selected'":"";?> value="halloffameplacment"><?php echo translate('halloffameplacment'); ?></option>
					<option <?php echo ($awardData['category']=="numberoffollowers")?"selected='selected'":"";?> value="numberoffollowers"><?php echo translate('numberoffollowers'); ?></option>
					<option <?php echo ($awardData['category']=="totalnumberofpersonalmessagessent")?"selected='selected'":"";?> value="totalnumberofpersonalmessagessent"><?php echo translate('totalnumberofpersonalmessagessent'); ?></option>
					<!--<option value="meanweightliftedinperiod"><?php echo translate('meanweightliftedinperiod'); ?></option> -->
					<option <?php echo ($awardData['category']=="numberofexercisestrained")?"selected='selected'":"";?> value="numberofexercisestrained"><?php echo translate('numberofexercisestrained'); ?></option>
					<option <?php echo ($awardData['category']=="effectiveness")?"selected='selected'":"";?> value="effectiveness"><?php echo translate('effectiveness'); ?></option>
					<option <?php echo ($awardData['category']=="wilks")?"selected='selected'":"";?> value="wilks"><?php echo translate('wilks'); ?></option>
            	</select>
			</div>
			<div class="clear"></div>
		</div>
		<?php
			$numOfRepetitionStyle = "";
			if($awardData['category'] != "effectiveness"){
				$numOfRepetitionStyle = "display:none;";
			}
		?>
		<div id="number-of-repetition" style="<?php echo $numOfRepetitionStyle; ?>" class="new-award-item">
			<div class="new-award-item-left">
				<label for="">Number of repetitions:</label>
			</div>
			<div class="new-award-item-right">
				<input type="text" value="<?php echo $awardData['num_of_repitition']; ?>" name="award-num-of-repetition" />
			</div>
			<div class="clear"></div>
		</div>
		
		<?php
			$awardSetsPerHourStyle = "";
			if($awardData['category'] != "effectiveness"){
				$awardSetsPerHourStyle = "display:none;";
			}
		?>
		<div id="sets-per-hour" style="<?php echo $awardSetsPerHourStyle ?>" class="new-award-item">
			<div class="new-award-item-left">
				<label for="">sets per hour:</label>
			</div>
			<div class="new-award-item-right">
				<input type="text" value="<?php echo $awardData['awardSetsPerHour']; ?>" name="award-sets-per-hour" />
			</div>
			<div class="clear"></div>
		</div>
		<?php
			$awardRepetitionsPerHourStyle = "";
			if($awardData['category'] != "effectiveness"){
				$awardRepetitionsPerHourStyle = "display:none;";
			}
		?>
		<div id="repetitions-per-hour" style="<?php echo $awardRepetitionsPerHourStyle ?>" class="new-award-item">
			<div class="new-award-item-left">
				<label for="">repetitions per hour:</label>
			</div>
			<div class="new-award-item-right">
				<input type="text" value="<?php echo $awardData['awardRepetitionsPerHour']?>" name="award-repetitions-per-hour" />
			</div>
			<div class="clear"></div>
		</div>
		
		<?php
			if($awardData['category'] == "volume" || $awardData['category'] =="" || $awardData['category'] =="effectiveness"){
				$awardFromDateStyle ="";
			}else{
				$awardFromDateStyle ="display:none;";
			}
		?>
		
		<div id="from-date" style="<?php echo $awardFromDateStyle?>" class="new-award-item">
			<div class="new-award-item-left">
				<label for=""><?php echo translate("from")?>:</label>
			</div>
			<div class="new-award-item-right">
				<input id="from-date-input" type="text" value="<?php if($awardData['awardFromDate']){ echo date("m/d/Y",$awardData['awardFromDate']);} ?>" name="award-from-date" />
			</div>
			<div class="clear"></div>
		</div>
		<?php
			$awardToDateStyle ="";
			if($awardData['category'] != "volume" && $awardData['category'] !="" &&$awardData['category'] !="effectiveness"){
				$awardToDateStyle ="display:none;";
			}
		?>
		<div id="to-date" style="<?php echo $awardToDateStyle?>" class="new-award-item">
			<div class="new-award-item-left">
				<label for=""><?php echo translate("to")?>:</label>
			</div>
			<div class="new-award-item-right">
				<input id="to-date-input" type="text" value="<?php if($awardData['awardFromDate']){ echo date("m/d/Y",$awardData['awardToDate']);} ?>" name="award-to-date" />
			</div>
			<div class="clear"></div>
		</div>
		
		<?php
		$periodTimeStyle = "";
		if($awardData['category'] != "volume" && $awardData['category'] !="" && $awardData['category'] !="effectiveness"){
				$periodTimeStyle ="display:none;";
			}
		?>
		<div id="period-time" style="<?php echo $periodTimeStyle; ?>" class="new-award-item">
			<div class="new-award-item-left">
				<label for=""><?php echo translate('period')?>:</label>
			</div>
			<div class="new-award-item-right">
				<select name="period-time">
					<option <?php echo ($awardData['periodTime'] == "aday")?"selected='selected'": "" ?> value="aday"><?php echo translate('day')?></option>
					<option <?php echo ($awardData['periodTime'] == "oneweek")?"selected='selected'": "" ?> value="oneweek"><?php echo translate('week')?></option>
					<option <?php echo ($awardData['periodTime'] == "onemonth")?"selected='selected'": "" ?> value="onemonth"><?php echo translate('month')?></option>
					<option <?php echo ($awardData['periodTime'] == "oneyear")?"selected='selected'": "" ?> value="oneyear"><?php echo translate('year')?></option>
					<option <?php echo ($awardData['periodTime'] == "lifetime")?"selected='selected'": "" ?> value="lifetime">lifetime</option>
				</select>
			</div>
			<div class="clear"></div>
		</div>
		<div id="requirement" class="new-award-item">
			<div class="new-award-item-left">
				<label for=""><?php echo translate('requirement');?>:</label>
			</div>
			<div class="new-award-item-right">
				<input type="text" value="<?php echo $awardData['requirement'] ?>" name="award-requirement" />
			</div>
			<div class="clear"></div>
		</div>
		<?php
		$bodyweightStyle = "";
		if($awardData['category'] != "volume" && $awardData['category'] != "weight" && $awardData['category'] !="" && $awardData['category'] !="effectiveness"){
			$bodyweightStyle = "display: none;";
		}
		?>
		<div id="body-weight" style="<?php echo $bodyweightStyle?>" class="new-award-item">
			<div class="new-award-item-left">
				<label for=""><?php echo translate('bodyweight');?>:</label>
			</div>
			<div class="new-award-item-right">
				<input type="text" value="<?php echo $awardData['bodyweight']?>" name="award-body-weight" />
			</div>
			<div class="clear"></div>
		</div>
		<?php
		$category_exerciseStyle = "";
		if($awardData['category'] != "volume" && $awardData['category'] != "weight" && $awardData['category'] != "halloffameplacment" && $awardData['category'] != "numberofexercisestrained" && $awardData['category'] != "bodyweight" && $awardData['category'] != "wilks"){
			$category_exerciseStyle = "display: none;";
		}
		?>
		<div id="categor_exercise" style="<?php echo $category_exerciseStyle ?>" class="new-award-item">
			<div class="new-award-item-left">
				<label for=""><?php echo translate('category')." ".translate('exercise');?>:</label>
			</div>
			<div class="new-award-item-right">
				<select class="selectbox"  id="select_category" name="select_category" onchange="updateOptions(document.new_award.select_category.options[document.new_award.select_category.selectedIndex].value, 'select_exercise');">
				<option value="" selected="selected">
				<?php echo translate('select_category'); ?>
				
				</option>
				<?php
			 
				foreach($EXERCISE_LIST as $key => $value)
				{
					$ex_id = $value['id'];
					
					$ex_list = $value['list'];
					$output = translate($value['name']);
					if(isset($awardData['category_exercise']) && ($awardData['category_exercise'] != "") && ($awardData['category_exercise'] == $key)){
				?>
					<option value="<?php echo $key ?>" selected="selected"><?php echo  translate($output) ?></option>
				<?php
					}else{
				?>
					<option value="<?php echo $key ?>"><?php echo  translate($output) ?></option>
				<?php
					}
				}
				?>
			</select>
			</div>
			<div class="clear"></div>
		</div>
		<?php
		$exerciseStyle = "";
		if($awardData['category'] != "volume" && $awardData['category'] != "weight" && $awardData['category'] != "halloffameplacment" && $awardData['category'] != "numberofexercisestrained" && $awardData['category'] != "bodyweight" && $awardData['category'] != "wilks"){
			$exerciseStyle = "display: none;";
		}
		?>
		<div id="exercise" style="<?php echo $exerciseStyle?>" class="new-award-item">
			<div class="new-award-item-left">
				<label for=""><?php echo translate('exercise');?>:</label>
			</div>
			<div class="new-award-item-right">
				<select id="select_exercise" name="exercise">
				<?php
					if(!isset($awardData['category_exercise']) || ($awardData['category_exercise'] =="")){
				?>
					<option value="" selected="selected">
					<?php echo translate('selectcategoryfirst'); ?>
					</option>
				<?php
					}else{
				?>
					<option value="" selected="selected">
					<?php echo translate('selectexercise'); ?>
					</option>
				<?php
						$exTempList = $EXERCISE_LIST[$awardData['category_exercise']]['list'];
						if(count($exTempList) > 0){
							foreach($exTempList as $k => $v)
							{
								if(isset($awardData['exercise']) && ($awardData['exercise'] == $v['id'])){
				?>
					<option value="<?php echo $v['id']?>" selected="selected">
					<?php echo translate($v['name']); ?>
					</option>			
				<?php
							
								}else{
				?>
					<option value="<?php echo $v['id']?>">
					<?php echo translate($v['name']); ?>
					</option>
				<?php
								}
							}
						}
				?>
				<?php
					}
				?>
				</select>
			</div>
			<div class="clear"></div>
		</div>
		<div class="new-award-item">
			<div class="new-award-item-left">
				<label for=""><?php echo translate('level')?>:</label>
			</div>
			<div class="new-award-item-right">
				<select class="select" id="category" name="level">
					<option <?php echo ($awardData['level'] == "novice")?"selected='selected'":"" ?> value="novice"><?php echo translate('novice')?></option>
					<option <?php echo ($awardData['level'] == "intermediate")?"selected='selected'":"" ?> value="intermediate"><?php echo translate('intermediate')?></option>
					<option <?php echo ($awardData['level'] == "advanced")?"selected='selected'":"" ?> value="advanced"><?php echo translate('advanced')?></option>
					<option <?php echo ($awardData['level'] == "expert")?"selected='selected'":"" ?> value="expert"><?php echo translate('expert')?></option>
					<option <?php echo ($awardData['level'] == "elite")?"selected='selected'":"" ?> value="elite"><?php echo translate('elite')?></option>
					<option <?php echo ($awardData['level'] == "worldclass")?"selected='selected'":"" ?> value="worldclass"><?php echo translate('worldclass')?></option>
            	</select>
			</div>
		<div class="clear"></div>
		</div>
		<div class="new-award-item">
			<div class="new-award-item-left">
				<label for=""><?php echo translate('points')?>:</label>
			</div>
			<div class="new-award-item-right">
				<input type="text" value="<?php echo $awardData['point']?>" name="award-point" />
			</div>
			<div class="clear"></div>
		</div>
		<div class="new-award-item">
			<div class="new-award-item-left">
				<label for=""><?php echo translate('uploadpic')?>:</label>
			</div>
			<div class="new-award-item-right">
				<input type="file" name="award-image" />
			</div>
			<div class="clear"></div>
		</div>
		<div class="new-award-item">
			<div class="new-award-item-left">
				<label for=""></label>
			</div>
			<div class="new-award-item-right">
				<input type="submit" value="<?php echo translate('save');?>" name="award-submit" />
			</div>
			<div class="clear"></div>
		</div>
	</div>
</form>
<script type="text/javascript">
	$(document).ready(function(){
		$("#category").change(function(){
			$category = $("#category option:selected").val();
			switch($category){
				case "volume":
					$("#exercise").show();
					$("#from-date").show();
					$("#to-date").show();
					$("#period-time").show();
					$("#body-weight").show();
					$("#categor_exercise").show();
					$("#gender-item").show();
					
					
					$("#number-of-repetition").hide();
					$("#sets-per-hour").hide();
					$("#repetitions-per-hour").hide();
					break;
				case "weight":
					$("#categor_exercise").show();
					$("#exercise").show();
					$("#body-weight").show();
					$("#gender-item").show();
					
					$("#number-of-repetition").hide();
					$("#sets-per-hour").hide();
					$("#repetitions-per-hour").hide();
					$("#from-date").hide();
					$("#to-date").hide();
					$("#period-time").hide();
					break;
				case "numberofconnections":
					$("#exercise").hide();
					$("#categor_exercise").hide();
					$("#number-of-repetition").hide();
					$("#body-weight").hide();
					$("#sets-per-hour").hide();
					$("#repetitions-per-hour").hide();
					$("#from-date").hide();
					$("#to-date").hide();
					$("#period-time").hide();
					$("#gender-item").hide();
					break;
				case "halloffameplacment":
					$("#exercise").show();
					$("#categor_exercise").show();
					$("#gender-item").show();
					
					$("#number-of-repetition").hide();
					$("#body-weight").hide();
					$("#sets-per-hour").hide();
					$("#repetitions-per-hour").hide();
					$("#from-date").hide();
					$("#to-date").hide();
					$("#period-time").hide();
					break;
				case "numberoffollowers":
					$("#exercise").hide();
					$("#categor_exercise").hide();
					$("#number-of-repetition").hide();
					$("#body-weight").hide();
					$("#sets-per-hour").hide();
					$("#repetitions-per-hour").hide();
					$("#from-date").hide();
					$("#to-date").hide();
					$("#period-time").hide();
					$("#gender-item").hide();
					break;
				case "totalnumberofpersonalmessagessent":
					$("#number-of-repetition").hide();
					$("#body-weight").hide();
					$("#exercise").hide();
					$("#categor_exercise").hide();
					$("#sets-per-hour").hide();
					$("#repetitions-per-hour").hide();
					$("#from-date").hide();
					$("#to-date").hide();
					$("#period-time").hide();
					$("#gender-item").hide();
					break;
				case "numberofexercisestrained":
					$("#exercise").show();
					$("#categor_exercise").show();
					$("#gender-item").show();
				
					$("#number-of-repetition").hide();
					$("#body-weight").hide();
					$("#sets-per-hour").hide();
					$("#repetitions-per-hour").hide();
					$("#from-date").hide();
					$("#to-date").hide();
					$("#period-time").hide();
					break;
				case "effectiveness":
					$("#number-of-repetition").show();
					$("#sets-per-hour").show();
					$("#repetitions-per-hour").show();
					$("#body-weight").show();
					$("#gender-item").show();
					$("#from-date").show();
					$("#to-date").show();
					$("#period-time").show();
					
					$("#categor_exercise").hide();
					$("#exercise").hide();
					$("#requirement").hide();
					break;
				case "wilks":
					$("#requirement").show();
					$("#categor_exercise").show();
					$("#exercise").show();
					$("#body-weight").show();
					$("#gender-item").show();
					
					$("#period-time").hide();
					$("#number-of-repetition").hide();
					$("#body-weight").hide();
					$("#sets-per-hour").hide();
					$("#repetitions-per-hour").hide();
					$("#from-date").hide();
					$("#to-date").hide();
					break;
				case "bodyweight":
					$("#requirement").show();
					$("#categor_exercise").show();
					$("#exercise").show();
					$("#gender-item").show();
					
					$("#body-weight").hide();
					$("#period-time").hide();
					$("#number-of-repetition").hide();
					$("#body-weight").hide();
					$("#sets-per-hour").hide();
					$("#repetitions-per-hour").hide();
					$("#from-date").hide();
					$("#to-date").hide();
					break;
				default:
					break;
			}
		});
		
		$(function(){
		Date.format = 'mm/dd/yyyy';
		$('#from-date-input').datePicker({autoFocusNextInput: true, startDate: '01/01/2011'});
		$('#to-date-input').datePicker({autoFocusNextInput: true, startDate: '01/01/2011'});
	});
	});
	
	// Dropdown boxes
	function updateOptions(chosen, nameofbox)
	{
		var selbox = document.getElementById(nameofbox);
		selbox.options.length = 0;
		 
		if (chosen == "") 
		{
			selbox.options[selbox.options.length] = new Option('<?php echo translate("selectcategoryfirst"); ?>','');
		}else{
			selbox.options[selbox.options.length] = new Option('<?php echo translate('selectexercise'); ?>','');
			<?php
			foreach($EXERCISE_LIST as $key => $value)
			{
				$ex_id = $value['id'];
				$ex_list = $value['list'];
				$output = translate($value['name']);
				echo "if(chosen == \"" . $key . "\") {\n";
				foreach($ex_list as $k => $v)
				{
					$output = translate($v['name']);
					echo "	selbox.options[selbox.options.length] = new Option('" . $output . "', '" . $v['id'] . "');\n";
				}
				echo "}\n";
			}
			?>
		}
	}
</script>